#include"gaussian.h"
#include"test_gaussian.h"
using namespace mylib;

int main() {
    Doub a[] = { 3,2,1,2,2,2,4,-2,-2 };
    Doub b[] = { 6,4,2};
    MatDoub aa(3, 3, a);
    aa.show(3,3);
    linalg::gaussj(aa);
    aa.show(3,3);

    MatDoub cc(3,3,a);
    VecDoub bb(3,b);
    linalg::gaussj2(cc,bb);
    cc.show(3,3);
    bb.show(3);
    VecDoub x(3);
    int n = x.size();
    x[n-1] = bb[n-1] / cc[n-1][n-1];
    for (int i = n-2; i > -1; i--)
    {  double tmp=0.0;
       for (int j = n-1; j > i; j--)
       {
            tmp += cc[i][j] * x[j];
       }
       x[i] = (bb[i] - tmp) / cc[i][i];   
    }
    x.show(n);
    

    return 0;
}